/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.SFA.ProductShow;

import java.io.Serializable;
import java.util.List;

import android.app.Fragment;
import android.app.ListFragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ListView;

import com.FrameWork.Entity.ProductEntity;
import com.SFA.R;
import com.SFA.OrderManagement.ProductDetailActivity;

public class ProductGridFragment extends Fragment {

	private ProductShowAdapter adapter= null;
	private GridView view = null;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		view = (GridView) inflater.inflate(R.layout.explorer_product_gridview, container, false);
		view.setOnItemClickListener(new OnItemClickListener(){
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				//查看该产品明细
				Intent intent = new Intent(getActivity(), ProductDetailActivity.class);
				intent.putExtra("DATA", (Serializable)adapter.getItem(arg2));
				getActivity().startActivity(intent);
			}

		});
		return view;
	}

	public void ShowProduct(List<ProductEntity> list) {

		adapter = new ProductShowAdapter(list,getActivity());
		view.setAdapter(adapter);

	}


	/*
	 * 0 是多图模式
	 * 1 是单图模式
	 */
	public void SetViewMode(int mode)
	{


		//控制模式显示
		if(mode ==1)
		{
			view.setNumColumns(1);
		}
		else
		{
			view.setNumColumns(4);//一行显示4个
		}

		if(adapter != null)
			adapter.setMode(mode);
	}



}
